/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vista;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import modelo.Moto;
import modelo.MotoManager;

/**
 *
 * @author Z510
 */
public class JIntFicheros extends javax.swing.JInternalFrame {

    String filename;
    MotoManager myManager;
    boolean flagIsTexto;
    
    /**
     * Creates new form JIntCrearBd
     */
    public JIntFicheros() {
        initComponents();
        
        
        filename = "";
        myManager = new MotoManager();
       // this.setLocationRelativeTo(null);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jScrollPane2 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        jLabelmensaje = new javax.swing.JLabel();
        BtnMostrarDom = new javax.swing.JButton();
        BtnMostrarSax = new javax.swing.JButton();
        BtnMostrarXml = new javax.swing.JButton();
        BtnMostrarTexto = new javax.swing.JButton();
        BtnMostrarBinario = new javax.swing.JButton();
        BtnMostrarArray = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea = new javax.swing.JTextArea();
        jPanelDatos = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldMarca = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldCilindrada = new javax.swing.JTextField();
        jTextFieldModelo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPotencia = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldCilindros = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldRefrigeracion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldPrecio = new javax.swing.JTextField();
        jPanelImage = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        BtnCancelar = new javax.swing.JButton();
        BtnAnyadir = new javax.swing.JButton();
        BtnGuardar = new javax.swing.JButton();

        jScrollPane2.setViewportView(jEditorPane1);

        setClosable(true);
        setMaximizable(true);
        setTitle("Ficheros");

        jLabelmensaje.setBackground(new java.awt.Color(255, 255, 153));
        jLabelmensaje.setText("<Fichero XML no seleccionado>");
        jLabelmensaje.setAlignmentY(0.0F);

        BtnMostrarDom.setBackground(new java.awt.Color(102, 255, 102));
        BtnMostrarDom.setText("Muestra DOM");
        BtnMostrarDom.setEnabled(false);
        BtnMostrarDom.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarDomActionPerformed(evt);
            }
        });

        BtnMostrarSax.setBackground(new java.awt.Color(102, 255, 102));
        BtnMostrarSax.setText("Muestra SAX");
        BtnMostrarSax.setEnabled(false);
        BtnMostrarSax.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarSaxActionPerformed(evt);
            }
        });

        BtnMostrarXml.setBackground(new java.awt.Color(102, 255, 102));
        BtnMostrarXml.setText("Mostrar XML");
        BtnMostrarXml.setEnabled(false);
        BtnMostrarXml.setRequestFocusEnabled(false);
        BtnMostrarXml.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarXmlActionPerformed(evt);
            }
        });

        BtnMostrarTexto.setBackground(new java.awt.Color(102, 255, 255));
        BtnMostrarTexto.setText("Muestra Texto");
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarTexto.setName(""); // NOI18N
        BtnMostrarTexto.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarTextoActionPerformed(evt);
            }
        });

        BtnMostrarBinario.setBackground(new java.awt.Color(102, 255, 255));
        BtnMostrarBinario.setText("Muestra Binario");
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarBinario.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarBinarioActionPerformed(evt);
            }
        });

        BtnMostrarArray.setBackground(new java.awt.Color(102, 255, 255));
        BtnMostrarArray.setText("Mostrar Array");
        BtnMostrarArray.setEnabled(false);
        BtnMostrarArray.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarArrayActionPerformed(evt);
            }
        });

        jTextArea.setEditable(false);
        jTextArea.setColumns(20);
        jTextArea.setRows(5);
        jTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(jTextArea);

        jPanelDatos.setEnabled(false);

        jLabel1.setText("Marca");

        jTextFieldMarca.setEditable(false);
        jTextFieldMarca.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jTextFieldMarcaActionPerformed(evt);
            }
        });
        jTextFieldMarca.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldMarcaKeyPressed(evt);
            }
        });

        jLabel2.setText("Modelo");

        jLabel3.setText("Cilindrada");

        jTextFieldCilindrada.setEditable(false);
        jTextFieldCilindrada.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyReleased(java.awt.event.KeyEvent evt)
            {
                jTextFieldCilindradaKeyReleased(evt);
            }
        });

        jTextFieldModelo.setEditable(false);
        jTextFieldModelo.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldModeloKeyPressed(evt);
            }
        });

        jLabel4.setText("Potencia");

        jTextFieldPotencia.setEditable(false);
        jTextFieldPotencia.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldPotenciaKeyPressed(evt);
            }
        });

        jLabel5.setText("Cilindros");

        jTextFieldCilindros.setEditable(false);
        jTextFieldCilindros.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldCilindrosKeyPressed(evt);
            }
        });

        jLabel6.setText("cc");

        jLabel7.setText("cv");

        jLabel8.setText("Refrigeracion");

        jTextFieldRefrigeracion.setEditable(false);
        jTextFieldRefrigeracion.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldRefrigeracionKeyPressed(evt);
            }
        });

        jLabel9.setText("Precio");

        jTextFieldPrecio.setEditable(false);
        jTextFieldPrecio.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldPrecioKeyPressed(evt);
            }
        });

        jPanelImage.setEnabled(false);

        javax.swing.GroupLayout jPanelImageLayout = new javax.swing.GroupLayout(jPanelImage);
        jPanelImage.setLayout(jPanelImageLayout);
        jPanelImageLayout.setHorizontalGroup(
            jPanelImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
        jPanelImageLayout.setVerticalGroup(
            jPanelImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 200, Short.MAX_VALUE)
        );

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setText("€");

        javax.swing.GroupLayout jPanelDatosLayout = new javax.swing.GroupLayout(jPanelDatos);
        jPanelDatos.setLayout(jPanelDatosLayout);
        jPanelDatosLayout.setHorizontalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldMarca)
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelDatosLayout.createSequentialGroup()
                                .addComponent(jTextFieldCilindrada, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel6))
                            .addGroup(jPanelDatosLayout.createSequentialGroup()
                                .addComponent(jTextFieldPotencia, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7))
                            .addComponent(jTextFieldCilindros, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldRefrigeracion, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelDatosLayout.createSequentialGroup()
                                .addComponent(jTextFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jPanelImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDatosLayout.setVerticalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldCilindrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldPotencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCilindros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldRefrigeracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10))
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(jPanelImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        BtnCancelar.setText("Cancelar");
        BtnCancelar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BtnCancelar.setEnabled(false);
        BtnCancelar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnCancelarActionPerformed(evt);
            }
        });

        BtnAnyadir.setText("Añadir");
        BtnAnyadir.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BtnAnyadir.setEnabled(false);
        BtnAnyadir.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnAnyadirActionPerformed(evt);
            }
        });

        BtnGuardar.setText("Guardar ficheros");
        BtnGuardar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BtnGuardar.setEnabled(false);
        BtnGuardar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabelmensaje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BtnMostrarDom, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarSax, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarXml, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarTexto, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                    .addComponent(jScrollPane1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BtnMostrarBinario, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarArray, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelDatos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(5, 5, 5))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BtnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(12, 12, 12)
                        .addComponent(BtnAnyadir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabelmensaje)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtnMostrarDom, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarSax, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarXml, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarTexto, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarBinario, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(BtnMostrarArray, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelDatos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnAnyadir, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BtnMostrarDomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarDomActionPerformed
        String cadena = "";

        //Show on screen the xml file
        cadena += "\t\tCOLECCION DE MOTOS. Fichero XML\n\n";

        cadena += myManager.showXML(filename);

        this.jTextArea.setText(cadena);

        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarDomActionPerformed

    private void BtnMostrarSaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarSaxActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Lectura SAX\n\n";
        cadena += myManager.ReadXML_Sax(filename);

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarSaxActionPerformed

    private void BtnMostrarXmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarXmlActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Archivo XML\n\n";
        cadena += myManager.showTextFile(filename);

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarXmlActionPerformed

    private void BtnMostrarTextoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarTextoActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Fichero de Texto\n\n";
        cadena += myManager.showTextFile(filename);

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarTextoActionPerformed

    private void BtnMostrarBinarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarBinarioActionPerformed
        String cadena = "";
        // Show on jtextArea the binary file
        cadena += "\t\tCOLECCION DE MOTOS. Fichero Binario\n\n";
        try {
            // myManager.writeBinaryFile(filename);
            myManager.readBinaryFile(filename);
        } catch (IOException ex) {
            // Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
            // EXCEPCIÓN MSG BOX

        }
        cadena += myManager.showColection();

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarBinarioActionPerformed

    private void BtnMostrarArrayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarArrayActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Array de Motos\n\n";

        if (flagIsTexto) {
            myManager.readTextFile(filename);
        } else {
            try {
                myManager.readBinaryFile(filename);
            } catch (IOException ex) {
                Logger.getLogger(JFrameFicheros.class.getName()).log(Level.SEVERE, null, ex);
                // MSG BOX EXCEPCIÓN
            }
        }

        cadena += myManager.showColection();

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarArrayActionPerformed

    private void jTextFieldMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldMarcaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldMarcaActionPerformed

    private void jTextFieldMarcaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldMarcaKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldMarcaKeyPressed

    private void jTextFieldCilindradaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCilindradaKeyReleased
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldCilindradaKeyReleased

    private void jTextFieldModeloKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldModeloKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldModeloKeyPressed

    private void jTextFieldPotenciaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldPotenciaKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldPotenciaKeyPressed

    private void jTextFieldCilindrosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCilindrosKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldCilindrosKeyPressed

    private void jTextFieldRefrigeracionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldRefrigeracionKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldRefrigeracionKeyPressed

    private void jTextFieldPrecioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldPrecioKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldPrecioKeyPressed

    private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelarActionPerformed
        jTextFieldMarca.setText("");
        jTextFieldModelo.setText("");
        jTextFieldRefrigeracion.setText("");
        //pendiente de solucionar imagen
        jTextFieldCilindrada.setText("");
        jTextFieldCilindros.setText("");
        jTextFieldPotencia.setText("");
        jTextFieldPrecio.setText("");

        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnCancelarActionPerformed

    private void BtnAnyadirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAnyadirActionPerformed
        jTextFieldMarca.setEditable(true);
        jTextFieldModelo.setEditable(true);
        jTextFieldCilindrada.setEditable(true);
        jTextFieldCilindros.setEditable(true);
        jTextFieldPotencia.setEditable(true);
        jTextFieldPrecio.setEditable(true);
        jTextFieldRefrigeracion.setEditable(true);
        //        jTextFieldIma.setEnabled(true);

        BtnGuardar.setEnabled(true);
        BtnAnyadir.setEnabled(false);
        BtnCancelar.setEnabled(true);

        jTextFieldMarca.requestFocus(true);
    }//GEN-LAST:event_BtnAnyadirActionPerformed

    private void BtnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnGuardarActionPerformed
        String marca, modelo, refrigeracion, imagen;
        int cilindrada, cilindros;
        double potencia, precio;

        try {
            marca = jTextFieldMarca.getText();
            modelo = jTextFieldModelo.getText();
            if (marca.equals("") || modelo.equals("")) {
                JOptionPane.showMessageDialog(null, "Debe introducir la marca y el modelo");
                return;
            }
            refrigeracion = jTextFieldRefrigeracion.getText();
            //pendiente de solucionar imagen
            imagen = "Falta imagen";
            cilindrada = Integer.parseInt(jTextFieldCilindrada.getText().equals("") ? "0" : jTextFieldCilindrada.getText());
            cilindros = Integer.parseInt(jTextFieldCilindros.getText().equals("") ? "0" : jTextFieldCilindros.getText());
            potencia = Double.parseDouble(jTextFieldPotencia.getText().equals("") ? "0" : jTextFieldPotencia.getText());
            precio = Double.parseDouble(jTextFieldPrecio.getText().equals("") ? "0" : jTextFieldPrecio.getText());

            Moto moto = new Moto(marca, modelo, cilindrada, potencia, cilindros, refrigeracion, precio, imagen);
            jTextFieldMarca.setText("");
            jTextFieldModelo.setText("");
            jTextFieldRefrigeracion.setText("");
            //pendiente de solucionar imagen
            jTextFieldCilindrada.setText("");
            jTextFieldCilindros.setText("");
            jTextFieldPotencia.setText("");
            jTextFieldPrecio.setText("");
            try {

                myManager.Add(moto);
                String filenameAux = filename.substring(0, filename.length() - 4);
                myManager.writeBinaryFile(filenameAux + ".dat");
                myManager.writeTextFile(filenameAux + ".txt");
                myManager.writeXML(filenameAux + ".xml");
                BtnGuardar.setEnabled(false);
                BtnAnyadir.setEnabled(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error guardando la nueva moto");
            }

        } catch (NumberFormatException numberFormatException) {
            JOptionPane.showMessageDialog(null, "Compruebe los datos introcidos.\n Cilindrada, potencia, cilindros y precio deben ser números.\n Use '.' como separador decimal");
        }

    }//GEN-LAST:event_BtnGuardarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAnyadir;
    private javax.swing.JButton BtnCancelar;
    private javax.swing.JButton BtnGuardar;
    private javax.swing.JButton BtnMostrarArray;
    private javax.swing.JButton BtnMostrarBinario;
    private javax.swing.JButton BtnMostrarDom;
    private javax.swing.JButton BtnMostrarSax;
    public javax.swing.JButton BtnMostrarTexto;
    private javax.swing.JButton BtnMostrarXml;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelmensaje;
    private javax.swing.JPanel jPanelDatos;
    private javax.swing.JPanel jPanelImage;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea;
    private javax.swing.JTextField jTextFieldCilindrada;
    private javax.swing.JTextField jTextFieldCilindros;
    private javax.swing.JTextField jTextFieldMarca;
    private javax.swing.JTextField jTextFieldModelo;
    private javax.swing.JTextField jTextFieldPotencia;
    private javax.swing.JTextField jTextFieldPrecio;
    private javax.swing.JTextField jTextFieldRefrigeracion;
    // End of variables declaration//GEN-END:variables

    private void MenuAbrirTextoActionPerformed(java.awt.event.ActionEvent evt)                                               
    {                                                   
        filename = "Motos.txt";
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarDom.setEnabled(false);
        BtnMostrarSax.setEnabled(false);
        BtnMostrarTexto.setEnabled(true);
        BtnMostrarArray.setEnabled(true);
        BtnMostrarXml.setEnabled(false);

        flagIsTexto = true;

        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }                                              

    private void MenuAbrirDomActionPerformed(java.awt.event.ActionEvent evt)                                             
    {                                                 
        filename = "Motos.xml";
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarDom.setEnabled(true);
        BtnMostrarSax.setEnabled(false);
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarArray.setEnabled(false);
        BtnMostrarXml.setEnabled(true);

        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }                                            

    private void MenuAbrirSaxActionPerformed(java.awt.event.ActionEvent evt)                                             
    {                                                 
        filename = "Motos.xml";
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarDom.setEnabled(false);
        BtnMostrarSax.setEnabled(true);
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarArray.setEnabled(false);
        BtnMostrarXml.setEnabled(true);

        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }                                            

    private void MenuAbrirBinarioActionPerformed(java.awt.event.ActionEvent evt)                                                 
    {                                                     
        filename = "Motos.dat";
        BtnMostrarBinario.setEnabled(true);
        BtnMostrarDom.setEnabled(false);
        BtnMostrarSax.setEnabled(false);
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarArray.setEnabled(true);
        BtnMostrarXml.setEnabled(false);

        flagIsTexto = false;
        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }                                                

    public void setMenuAbrirBinario() {
        this.MenuAbrirBinarioActionPerformed(null);
    }

    public void setMenuAbrirDom() {
        this.MenuAbrirDomActionPerformed(null);
    }

    public void setMenuAbrirSax() {
        this.MenuAbrirSaxActionPerformed(null);
    }

    public void setMenuAbrirTexto() {
        this.MenuAbrirTextoActionPerformed(null);
    }
}
